<template>
  <div style="height:100%;">
    <el-empty v-if="data.length == 0" description="暂无数据"></el-empty>
    <el-tree v-if="data.length > 0" :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
  </div>
</template>
<script>
import { sessionArchivingDepartmentGet } from '../../../../api/index';

export default {
  data() {
    return {
      data: [],
      defaultProps: {
        label: 'label',
        children: 'children'
      },
    };
  },
  created() {
    this.getinit();
  },

  methods: {
    //初始化
    getinit() {
      this.data = [];
      sessionArchivingDepartmentGet().then((res) => {
        if (res.code == 0) {
          if (res.list.length > 0) {
            res.list.forEach((item, i) => {
              this.data.push({
                label: item.vName,
                id: item.vId,
                did: item.dId
              })
              this.bumenList(item, i, this.data);
            })
          }
        } else {
          this.$message(res.msg);
        }
      })
    },
    //循环部门
    bumenList(item, i, arr) {
      if (item.childList.length > 0) {
        arr[i].children = [];
        item.childList.forEach((e, index) => {
          arr[i].children.push({
            label: e.vName,
            id: e.vId,
            did: e.dId
          })
          this.bumenList(e, index, arr[i].children);
        })
      }
    },
    //点击获取成员
    handleNodeClick(data) {
      this.$emit("BMactive", data)
    },
  }
};
</script>

<style scoped>
/deep/ :focus {
    outline: 0;
}
</style>